<template>
  <div class="container">
    <data-view
      ref="dataview"
      :propViewKey="propViewKey"
      :propFlowKey="propFlowKey"
      :propPreQueryWrapper="propPreQueryWrapper"
      :propsDisableDbClick="formConfig.propsDisableDbClick"
      :propShowClose="propShowClose"
      @closewin="closeWin"
      @extra-button-click="handleExtraButton"
      @view-ready="viewReady"
      @edit-input="rowEditInput"
      :propViewForm="propViewForm ? propViewForm : 'frame/data-view/detail-model.vue'"
    />
  </div>
</template>

<script>
/* eslint-disable*/
export default {
  name: 'indexModel',
  props:[
    'propViewKey',
    'propFlowKey',
    'propPreQueryWrapper',
    'propShowClose',
    'propViewForm',
    'rowEditParam'  //行编辑后参数，键值对格式，编辑后将追加到行数据里面，比如{deptId:11}
  ],
  data() {
    return {
      formConfig: {}
    }
  },
  methods: {
    //按钮事件
    handleExtraButton(param) {
      console.log('param', param)
      //代码需要包裹一层，不然里面包含return等语句时，会报错
      try {
        let fun =  eval('(param) => { '+ this.formConfig.listExtraButtonClick + '}')
        fun(param)
      }catch (e) {
        console.error('indexModel.extraButtonClick.error')
        console.error('#########js代码#########')
        console.error(param.extraButtonClickParam.extraButtonClick)
        console.error('#########异常原因#########')
        console.error(e)
      }
    },

    //查询数据
    fetchData() {
      this.$refs.dataview.fetchData()
    },
    viewReady(){
      this.formConfig = this.$refs.dataview.formConfig
    },
    closeWin() {
      this.$emit('closewin')
    },

    //行编辑事件
    rowEditInput({ row, column }) {
      if (this.rowEditParam) {
        Object.keys(this.rowEditParam).forEach(key => {
          this.$set(row, key, this.rowEditParam[key])
        })
      }
    }
  },
  mounted() {
    console.log(`indexModel，propViewKey=${this.propViewKey}，propFlowKey=${this.propFlowKey}`)
  }
}
</script>

<style lang="scss" scoped>
  .container {
    height: 100%;
    background-color: #fff;
  }
</style>
